<!--
 * @Description: 周计划
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2023-03-14 15:36:31
 * @LastEditTime: 2023-05-25 14:53:19
 * @FilePath: \cscec-pms-admin\src\views\construction\weekPlan\weekPlanView.vue
-->
<template>
  <base-breadcrumb
    :title="breadcrumb"
    :breadcrumb="!isAudit"
  >
  <a-spin :spinning="loading">
  <LastWeekPlan :isAudit="isAudit" businessType="0" :allData="allData0"></LastWeekPlan>
   <ThisWeekPlan :isAudit="isAudit" businessType="1" :allData="allData1" ></ThisWeekPlan>
   <NextWeekPlan :isAudit="isAudit" businessType="2" :allData="allData2"></NextWeekPlan>
    <div
      v-if="!isConsultation"
      class="page-btn-right-top"
    >
      <a-button
        v-if="!isDetail && !isAudit"
        type="primary"
        :loading="submiting"
        @click="handleSubmit(0)"
        style="margin-right: 10px"
      >
        保存草稿
      </a-button>
      <a-button
        v-if="!isDetail && !isAudit"
        type="primary"
        :loading="submiting"
        @click="handleSubmit(1)"
        style="margin-right: 10px"
      >
        提交
      </a-button>
      <a-button @click="$close">
        关闭
      </a-button>
    </div>
     <!-- 选择审批人 -->
      <selectApprover
         :businessId="businessId"
         :processConfig="setProcessConfig"
       />
       <!-- 选择审批人 -->
  </a-spin>
  </base-breadcrumb>
</template>
<script>
import LastWeekPlan from './components/weekPlanDetail'
import ThisWeekPlan from './components/weekPlanDetail'
import NextWeekPlan from './components/weekPlanDetail'
import weekPlanApi from '@/api/construction/weekPlanApi'
import Vue from 'vue'
export default {
  name: 'weekPlanView' + Date.now(),
  props: {
    // 是否作为审批详情
    isAudit: {
      type: Boolean,
      default: false
    },
    // 是否作为意见征询
    isConsultation: {
      type: Boolean,
      default: false
    }
  },
  components: {
    LastWeekPlan,
    ThisWeekPlan,
    NextWeekPlan
  },
  data() {
    return {
      allData0:  {},
      allData1:  {},
      allData2:  {},
      // 面包屑名字
      breadcrumb: '',
      planId: '',
      // 提交
      submiting: false,
      // 表格加载
      loading: false,
      // 流程配置
      processConfig: null,
      //点击提交发送流程配置值
      setProcessConfig: null,
      // 业务id
      businessId: null,
    }
  },
  computed: {
    // 是查看
    isDetail() {
      return this.$route.query.pageType === 'detail' || this.isAudit
    }
  },
  async mounted() {
    this.setBreadcrumb()
    this.init()
    this.processConfig = await this.$getConfigFn('week_plan')
  },
  methods: {
    init() {
      const { planId,businessId} = this.$route.query
      this.planId = planId || businessId
      if (planId || businessId) {
        this.loading = true;
        const fun = this.isDetail ? weekPlanApi.weekPlanTileSearch :  weekPlanApi.weekPlanDetailSearch
        fun({planId: this.planId}).then(res => {
          if (res.data) {
            this.loading = false;
            const { data } = res
            if (data['0']) {
              this.allData0 = data['0']
            }
            if (data['1']) {
              this.allData1 = data['1']
            }
            if (data['2']) {
              this.allData2 = data['2']
            }
          }
        })
      }
    },
    /**
     * @description: 设置面包屑名字
     * @param {void}
     * @return {void}
     */
    setBreadcrumb() {
      const text = {
        detail: '查看',
        update: '编辑'
      }
      this.breadcrumb = `${text[this.$route.query.pageType]}周计划`
    },
    /**
     * @description: 提交
     * @param {string} auditStatus 操作类型
     * @return {void}
     */
    handleSubmit(auditStatus) {
      this.setProcessConfig = null
      this.submitApprovalConfirm(auditStatus === 1 ? this.processConfig : 6, (flag) => {
        if (!flag) return
        const { planId } = this.$route.query
        this.submiting = true
        weekPlanApi
          .weekPlanSubmitApproval({ auditStatus, planId })
          .then((res) => {
            if (res.code === 200 || res.data?.code === 200) {
              this.$message.success('操作成功！')
              // 提交成功后关闭页面
              if (auditStatus === 1) {
                this.setProcessConfig = this.processConfig
                this.businessId = res.data?.id
                //this.$close()
              }
            }
          })
          .catch((err) => {
            console.log(err)
          })
          .finally(() => {
            this.submiting = false
          })
      })
    },
  }
}
</script>
<style lang="less">
.row-active {
  background-color: #e6f7ff;
}
</style>
<style lang="less" scoped>

</style>
